﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.DAO;
using Com.CMS263.PO;
using System.Xml;
using Com.CMS263.Util;
namespace Com.CMS263.BLL
{
    public abstract class BaseBLL<T>
    {
        public abstract T GetModel();
        private readonly BaseService _BaseServer = new BaseService();


        
        /// <summary>
        /// 
        /// </summary>
        /// <returns>bool</returns>
        public bool Add() 
        {
            return _BaseServer.Add(this.GetModel());

        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns>bool</returns>
        public bool Delete() 
        {
            return _BaseServer.Delete(this.GetModel());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="HQL">string HQL</param>
        /// <returns>bool</returns>
        public   bool Delete(string HQL) 
        {
            return _BaseServer.Delete(HQL);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns>bool</returns>
        public bool UpDate() 
        {
            return _BaseServer.UpDate(this.GetModel());
        }

 
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T">T</typeparam>
        /// <param name="t">T</param>
        /// <param name="id">id(int)</param>
        /// <returns>T</returns>
        public T GetModel<T>(T t,int id) 
        {
            return _BaseServer.GetItemById<T>(t, id);
        }
        /// <summary>
        /// return IList<T>
        /// </summary>
        /// <typeparam name="T"T</typeparam>
        /// <param name="t">T</param>
        /// <returns>List<T></returns>
        public IList<T> GetModelList(T t) 
        {
            return _BaseServer.GetItemList<T>(t);
        }

        /// <summary>
        /// return IList
        /// </summary>
        /// <typeparam name="T">T</typeparam>
        /// <param name="t">T</param>
        /// <returns>List</returns>
        public IList<T> GetModelList(String hql)
        {
            return _BaseServer.GetItemList<T>(hql);
        }
        /// <summary>
        /// HQL 传参 查询 带分页 
        /// </summary>
        /// <param name="hql">hql语句</param>
        /// <param name="param">参数</param>
        /// <param name="first">开始条数</param>
        /// <param name="end">每页显示的条数</param>
        /// <returns></returns>
        public IList<T> FindList(String hql, Dictionary<string, object> param, int? first, int? end)
        {
            return _BaseServer.FindList<T>(hql, param, first, end) ;
        }



        /// <summary>
        /// 根据hql语句返回实体类
        /// </summary>
        /// <param name="HQL"></param>
        /// <returns></returns>
        public T GetModelById(string HQL)
        {
            return _BaseServer.GetItemByHQL<T>(HQL);
        }

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="obj"></param>
        public void Add(Object obj)
        {
            _BaseServer.Add(obj);
        }
        /// <summary>
        /// 返回一个结果
        /// </summary>
        /// <param name="hql"></param>
        /// <returns></returns>
        public object GetValue(string hql)
        {
            return _BaseServer.GetValue(hql);
        }
        /// <summary>
        /// 根据Id、查询实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public object FindModelById(string model, int id)
        {
            return _BaseServer.FindModelById(model, id);
        }
        /// <summary>
        /// 省市区，查询根据code
        /// </summary>
        /// <param name="p"></param>
        /// <param name="proCode"></param>
        /// <returns></returns>
        public object FindModelByCode(string model, string Code)
        {
            return _BaseServer.FindModelByCode(model,Code);
        }

        /// <summary>
        /// 根据实体对象名称和ID删除数据
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Delete(string Model, int id)
        {
            return _BaseServer.Delete(Model, id);
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        public bool BatchDelete(string model, string ids)
        {
            return _BaseServer.BatchDelete(model, ids);
        }
        /// <summary>
        /// 批量审核数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="id"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        public bool BatchCheck(string model, string ids, bool flag)
        {
            return _BaseServer.BatchCheck(model, ids,flag);
        }
    }
}
